﻿using System;
using Ninject;
using System.Web;
using System.Web.Routing;
using System.Web.Mvc;
using PromoCodes_Models.Abstract;
using PromoCodes_Models.Entities;
using PromoCodes_Models.Concrete;

namespace PromoCodes_GUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel kernel;

        public NinjectControllerFactory()
        {
            kernel = new StandardKernel();

            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)kernel.Get(controllerType);
        }

        public void AddBindings()
        {
            kernel.Rebind<IRepository<Product>>().To<EFProductRepository>();
            kernel.Rebind<IRepository<Promotion>>().To<EFPromotionRepository>();
        }
    }
}